Win32: move CoInitialize to dnd init
authorPaolo Borelli <pborelli@gnome.org>
Mon, 14 Dec 2015 18:40:25 +0000 (19:40 +0100)
committerPaolo Borelli <pborelli@gnome.org>
Thu, 17 Dec 2015 16:18:01 +0000 (17:18 +0100)
Functions requiring CoInitialize are called just in two places:
 - the filechooser thread which calls its own CoInitializeEx
 - the dnd code

Moving CoInitialize in the dnd specific init is cleaner and
we can pair it with the corresponding CoUninitialize since
CoUninitialize should be called as many times as CoInitialize.
Note that it is ok to call this function multiple times, so it
will not break if another codepath will need it in the future.

The patch also replaces the deprecated CoInitialize with the
equivalent call to CoInitializeEx (already used in the filechooser).

gdk/win32/gdkdnd-win32.c
gdk/win32/gdkmain-win32.c

index e1d5d104c1976e451e6cdcc8728e9cee3690d385..376ea0f654682a9e93d6bfb57e93fe9ea25a4352 100644 (file)
@@ -1571,6 +1571,8 @@ add_format (GArray *fmts,
 void
 _gdk_dnd_init (void)
 {
+  CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
+
   if (getenv ("GDK_WIN32_USE_EXPERIMENTAL_OLE2_DND"))
     use_ole2_dnd = TRUE;
 
@@ -1617,6 +1619,8 @@ _gdk_win32_dnd_exit (void)
     {
       OleUninitialize ();
     }
+
+  CoUninitialize ();
 }
 
 /* Source side */
index 64d5654bf30d337f47c03e54f4bed65e664b9d44..c66b54090904ff00caceb49951ea12c5fd7af1ce 100644 (file)
@@ -97,8 +97,6 @@ _gdk_win32_windowing_init (void)
   GDK_NOTE (EVENTS, g_print ("input_locale:%p, codepage:%d\n",
                             _gdk_input_locale, _gdk_input_codepage));
 
-  CoInitialize (NULL);
-
   _gdk_selection = gdk_atom_intern_static_string ("GDK_SELECTION");
   _wm_transient_for = gdk_atom_intern_static_string ("WM_TRANSIENT_FOR");
   _targets = gdk_atom_intern_static_string ("TARGETS");